package com.naza.rpc.register;

import com.naza.rpc.client.ConsClient;
import com.naza.rpc.client.ZookeeperClient;
import com.naza.rpc.model.ServiceInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *  zookeeper registry
 */
public class ZookeeperRegister implements Registry {

    private static final Logger LOG = LoggerFactory.getLogger(ZookeeperRegister.class);

    ZookeeperClient client = ZookeeperClient.getINSTANCE();

    @Override
    public void register(ServiceInstance serviceInstance) {
        try {
            client.registerInstance(serviceInstance.getServiceName(),serviceInstance);
        } catch (Exception e) {
            LOG.error("Error in register service to zookeeper.",e);
        }
    }

    @Override
    public void deRegister(ServiceInstance serviceInstance) {
        try {
            client.deRegisterInstance(serviceInstance.getServiceName(),serviceInstance);
        } catch (Exception e) {
            LOG.error("Error in deRegister service to zookeeper.",e);
        }
    }
}
